package org.linlinjava.litemall.db.service;

 
import org.linlinjava.litemall.db.dao.LumiereSubscribeRuleMapper;
import org.linlinjava.litemall.db.domain.*;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class LumiereSubscribeRuleService {
    @Resource
    private LumiereSubscribeRuleMapper lumiereSubscribeRuleMapper;

    public List<LumiereSubscribeRule> querySubscribeRule(Integer subscribeId) {
        LumiereSubscribeRuleExample example = new LumiereSubscribeRuleExample();
        LumiereSubscribeRuleExample.Criteria criteria = example.createCriteria();

        example.or().andLogicalDeleted(true).andSubscribeIdEqualTo(subscribeId).andStatusEqualTo(1);
        return lumiereSubscribeRuleMapper.selectByExample(example);
    }

    public void add(LumiereSubscribeRule lumiereSubscribeRule){
        lumiereSubscribeRuleMapper.insertSelective(lumiereSubscribeRule);
    }

    public void update(LumiereSubscribeRule lumiereSubscribeRule){
        lumiereSubscribeRuleMapper.updateByPrimaryKeySelective(lumiereSubscribeRule);
    }

    public LumiereSubscribeRule queryOne(Integer subscribeId,int type){
        LumiereSubscribeRuleExample example = new LumiereSubscribeRuleExample();
        example.createCriteria().andSubscribeIdEqualTo(subscribeId).andRuleTypeEqualTo((byte) type);
       return  lumiereSubscribeRuleMapper.selectOneByExampleSelective(example);
    }

    public LumiereSubscribeRule queryByPrimaryKey(Integer id){
        return lumiereSubscribeRuleMapper.selectByPrimaryKey(id);
    }

    public LumiereSubscribeRule queryBySubscibeAndRuleId(Integer subscribeId,Integer ruleId){
        LumiereSubscribeRuleExample example = new LumiereSubscribeRuleExample();
        example.createCriteria().andSubscribeIdEqualTo(subscribeId).andIdEqualTo(ruleId);
        return lumiereSubscribeRuleMapper.selectOneByExampleSelective(example);
    }

    public LumiereSubscribeRule findById(Integer id) {
        return lumiereSubscribeRuleMapper.selectByPrimaryKey(id);
    }

}
